<html>

<style>
    * {
        margin: 0;
    }

    #content {
        color: white;
        position: absolute;
        left: -20px;
        top: -10px;
        white-space: pre-wrap;
        height: 200px;
        overflow: auto;
    }
</style>

<script type="importmap">
	{
	  "imports": {
		"three": "../../three.js-r151/build/three.module.js",
		"three/addons/": "../../three.js-r151/examples/jsm/"
	  }
	}
</script>

<body>
    <div id="content">
        拉伸几何体ExtrudeGeometry和上节课讲到的轮廓填充几何体ShapeGeometry一样，都是基于一个基础的平面轮廓Shape进行变换，生成一个几何体。
    </div>
    <div id="canvas"></div>

    <script type="module">
        import * as THREE from 'three';
        import { OrbitControls } from 'three/addons/controls/OrbitControls.js';

        // 1. 必须创建的三大件
        // 1.1 三维场景Scene, 类似创建了个世界，三维世界
        const scene = new THREE.Scene();

        // 添加辅助坐标系
        const axesHelper = new THREE.AxesHelper(5);
        scene.add(axesHelper);

        // 1.2 相机
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.set(12, 12, 12)

        // 1.3 渲染器
        const renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        let canvasDom = document.getElementById("canvas");
        canvasDom.appendChild(renderer.domElement);

        function render() {
            renderer.render(scene, camera);
            requestAnimationFrame(render)
        }
        render();

        // 2. 设置相机控件轨道控制器OrbitControls
        new OrbitControls(camera, canvasDom);

        // 3. 拉升成立方体
        // Shape表示一个平面多边形轮廓
        const shape = new THREE.Shape([
            // 按照特定顺序，依次书写多边形顶点坐标
            new THREE.Vector2(-5, -5),
            new THREE.Vector2(-6, 0),
            new THREE.Vector2(0, 5),
            new THREE.Vector2(6, 0),
            new THREE.Vector2(5, -5),
        ]);

        //拉伸造型
        const geometry = new THREE.ExtrudeGeometry(
            shape, //二维轮廓
            {
                depth: 3, //拉伸长度
                bevelThickness: 5, //倒角尺寸:拉伸方向
                // bevelSize: 5, //倒角尺寸:垂直拉伸方向
                // bevelSegments: 20, //倒圆角：倒角细分精度，默认3
            }
        );

        const material = new THREE.LineBasicMaterial({ color: 'white' });
        const line = new THREE.Line(geometry, material);
        scene.add(line)


    </script>
</body>

</html>